package vista;

import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import modelo.Ejemplo;
import modelo.FuncionesAdalaine;
import modelo.RedAdalaine;
import modelo.tabla.ModeloTablaDatos;

/**
 *
 * @author Marlon
 */
public class FrmIniciarEntrenamiento extends javax.swing.JDialog {

    private RedAdalaine redAdalaine;
    private List<Ejemplo> listEjemplos;
    private List<Double> vSalidaRed;
    private int numEjemplos;

    /** Creates new form FrmIniciarEntrenamiento */
    public FrmIniciarEntrenamiento(java.awt.Frame parent, boolean modal,
            RedAdalaine redAdalaine, List<Ejemplo> listEjemplos) {
        super(parent, modal);
        this.redAdalaine = redAdalaine;
        this.listEjemplos = listEjemplos;
        numEjemplos = listEjemplos.size();
        vSalidaRed = new ArrayList<Double>(numEjemplos);
        initComponents();

        initDatos();
        setLocationRelativeTo(null);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        tbar = new javax.swing.JToolBar();
        jSeparator1 = new javax.swing.JToolBar.Separator();
        btnGuardar = new javax.swing.JButton();
        jSeparator2 = new javax.swing.JToolBar.Separator();
        btnSalir = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        scrollPane = new javax.swing.JScrollPane();
        tableMPesos = new javax.swing.JTable();
        jLabel2 = new javax.swing.JLabel();
        txtBias = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        txtError = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        txtFactorAprendizaje = new javax.swing.JTextField();
        btnIniciar = new javax.swing.JButton();
        btnActualizar = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtaSalida = new javax.swing.JTextArea();
        lblResultado = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Iniciar entrenamiento");

        tbar.setBackground(new java.awt.Color(246, 246, 246));
        tbar.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        tbar.setFloatable(false);
        tbar.setRollover(true);
        tbar.setPreferredSize(new java.awt.Dimension(100, 31));

        jSeparator1.setForeground(new java.awt.Color(246, 246, 246));
        jSeparator1.setEnabled(false);
        jSeparator1.setOpaque(true);
        jSeparator1.setRequestFocusEnabled(false);
        jSeparator1.setSeparatorSize(new java.awt.Dimension(437, 20));
        tbar.add(jSeparator1);

        btnGuardar.setFont(new java.awt.Font("Segoe UI", 1, 11));
        btnGuardar.setText("Guardar");
        btnGuardar.setFocusable(false);
        btnGuardar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnGuardar.setMargin(new java.awt.Insets(3, 15, 3, 15));
        btnGuardar.setMaximumSize(new java.awt.Dimension(117, 27));
        btnGuardar.setMinimumSize(new java.awt.Dimension(117, 27));
        btnGuardar.setPreferredSize(new java.awt.Dimension(117, 27));
        btnGuardar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        tbar.add(btnGuardar);

        jSeparator2.setEnabled(false);
        jSeparator2.setSeparatorSize(new java.awt.Dimension(10, 25));
        tbar.add(jSeparator2);

        btnSalir.setFont(new java.awt.Font("Segoe UI", 1, 11));
        btnSalir.setText("Salir");
        btnSalir.setFocusable(false);
        btnSalir.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnSalir.setMargin(new java.awt.Insets(3, 14, 3, 14));
        btnSalir.setMaximumSize(new java.awt.Dimension(117, 27));
        btnSalir.setMinimumSize(new java.awt.Dimension(117, 27));
        btnSalir.setPreferredSize(new java.awt.Dimension(117, 27));
        btnSalir.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSalirActionPerformed(evt);
            }
        });
        tbar.add(btnSalir);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "DATOS", javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI", 0, 12))); // NOI18N

        jLabel1.setFont(new java.awt.Font("Segoe UI", 0, 12));
        jLabel1.setText("Matriz de pesos");

        scrollPane.setPreferredSize(new java.awt.Dimension(452, 402));

        tableMPesos.setFont(new java.awt.Font("Segoe UI", 0, 12));
        tableMPesos.setFillsViewportHeight(true);
        scrollPane.setViewportView(tableMPesos);

        jLabel2.setFont(new java.awt.Font("Segoe UI", 0, 12));
        jLabel2.setText("Bias");

        txtBias.setFont(new java.awt.Font("Segoe UI", 0, 12));
        txtBias.setEnabled(false);

        jLabel3.setFont(new java.awt.Font("Segoe UI", 0, 12));
        jLabel3.setText("Error esperado");

        txtError.setFont(new java.awt.Font("Segoe UI", 0, 12));
        txtError.setEnabled(false);

        jLabel4.setFont(new java.awt.Font("Segoe UI", 0, 12));
        jLabel4.setText("Factor de aprendizaje");

        txtFactorAprendizaje.setFont(new java.awt.Font("Segoe UI", 0, 12));
        txtFactorAprendizaje.setEnabled(false);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel3)
                    .addComponent(jLabel2)
                    .addComponent(jLabel1))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(txtBias, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtError, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 123, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 160, Short.MAX_VALUE)
                        .addComponent(jLabel4)
                        .addGap(18, 18, 18)
                        .addComponent(txtFactorAprendizaje, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(scrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 536, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(32, 32, 32)
                        .addComponent(jLabel1))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addComponent(scrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(17, 17, 17)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtBias, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtError, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(txtFactorAprendizaje, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        btnIniciar.setFont(new java.awt.Font("Segoe UI", 0, 12));
        btnIniciar.setText("Iniciar");
        btnIniciar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnIniciarActionPerformed(evt);
            }
        });

        btnActualizar.setFont(new java.awt.Font("Segoe UI", 0, 12));
        btnActualizar.setText("Actualizar");

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "RESULTADO", javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI", 0, 12))); // NOI18N

        txtaSalida.setColumns(70);
        txtaSalida.setEditable(false);
        txtaSalida.setRows(20);
        txtaSalida.setWrapStyleWord(true);
        jScrollPane1.setViewportView(txtaSalida);

        lblResultado.setFont(new java.awt.Font("Segoe UI", 0, 12)); // NOI18N

        jLabel5.setFont(new java.awt.Font("Segoe UI", 0, 12));
        jLabel5.setText("SALIDA");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 636, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(lblResultado, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 385, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblResultado, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(btnIniciar, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btnActualizar, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
            .addComponent(tbar, javax.swing.GroupLayout.DEFAULT_SIZE, 688, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(tbar, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnIniciar)
                    .addComponent(btnActualizar))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalirActionPerformed
        this.setVisible(false);
    }//GEN-LAST:event_btnSalirActionPerformed

    private void btnIniciarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnIniciarActionPerformed
        // Normalizando la salida
        for (Ejemplo ejemplo : listEjemplos) {
            ejemplo.setSalida(0, ejemplo.getSalida(0) / redAdalaine.getNormalizador());
        }


        // Transformar el List<Ejemplo>
        for (Ejemplo ejemplo : listEjemplos) {
            ejemplo.addEntrada(0, 1.0f);
        }


        double errorDeseado = redAdalaine.getErrorEsperado();
        double errorCalculado = 100.0f;
        double salida;
        boolean cambio;
        int epoca = 0;
        String s;
        while (errorCalculado >= errorDeseado && epoca < 50) {
            // PARA TODOS LOS EJEMPLOS
            // INICIAMOS LA EPOCA
            epoca++;
            System.out.printf("\n<<EPOCA %d>>\n", epoca);
            s = "\n<<EPOCA " + (epoca) + ">>\n";
            txtaSalida.append(s);
            int numEjemplo = 0;
            vSalidaRed = new ArrayList<Double>(numEjemplos);
            for (Ejemplo ejemplo : listEjemplos) {
                numEjemplo++;
                System.out.printf("**EJEMPLO %d**\n", numEjemplo);
                s = "**EJEMPLO " + (numEjemplo) + "**\n";
                txtaSalida.append(s);
                for (int j = 0; j < redAdalaine.getNumNeurSalida(); j++) {
                    salida = FuncionesAdalaine.fPropagacion(redAdalaine.getFilaPesos(j), ejemplo.getvEntrada());
                    System.out.printf("[SALIDA DE LA RED NEURONA %d]: %.4f",
                            j + 1, salida);
                    s = "[SALIDA DE LA RED NEURONA %d]: %.4f";
                    s = String.format(s, j + 1, salida);
                    txtaSalida.append(s);
                    System.out.printf("   --   [TARGET %d]: %.4f",
                            j + 1, ejemplo.getSalida(j));
                    s = "   --   [TARGET %d]: %.4f";
                    s = String.format(s, j + 1, ejemplo.getSalida(j));
                    // s = "   --   [TARGET " + (j + 1) + "]: " + ejemplo.getSalida(j);
                    txtaSalida.append(s);
                    cambio = (salida != ejemplo.getSalida(j));
                    System.out.printf("\t --> y%st: %s se cambian pesos\n",
                            cambio ? "!=" : "==", cambio ? "" : "no");
                    s = "\t --> y" + (cambio ? "!=" : "==") + "t: " + (cambio ? "" : "no") + "se cambian pesos\n";
                    txtaSalida.append(s);
                    vSalidaRed.add(salida);
                }
                String compara = comparar(vSalidaRed, ejemplo.getvSalida(), numEjemplo);
                if (!compara.equals("")) {
                    // Hay cambio de pesos para el ejemplo
                    StringTokenizer st = new StringTokenizer(compara);
                    double cambioPeso;
                    while (st.hasMoreTokens()) {
                        int j = Integer.parseInt((String) st.nextToken());
                        for (int i = 0; i < redAdalaine.getNumNeurEntrada() + 1; i++) {
                            cambioPeso = FuncionesAdalaine.cambiarPeso(redAdalaine.getFactorAprendizaje(),
                                    ejemplo.getSalida(j), vSalidaRed.get(numEjemplo - 1), ejemplo.getEntrada(i));

                            redAdalaine.setPeso(j, i, redAdalaine.getPeso(j, i) + cambioPeso);
                        }
                    }
                }
                mostrarResultados();
            }
            System.out.printf("<<FIN EPOCA %d>>\n", epoca);
            s = "<<FIN EPOCA %d>>\n";
            s = String.format(s, epoca);
            txtaSalida.append(s);

            // CALCULANDO EL ERROR
            errorCalculado = 0.0f;
            int i = 0;
            for (Ejemplo ejemplo : listEjemplos) {
                errorCalculado += Math.pow(ejemplo.getSalida(0) - vSalidaRed.get(i), 2);
                i++;
            }
            errorCalculado = errorCalculado / 2;
            System.out.printf("ErrorCalculado >= ErrorDeseado? ===> %s\n%.3f   %.3f\n", (errorCalculado >= errorDeseado) ? "SI" : "NO", errorCalculado, errorDeseado);
            s = "ErrorCalculado >= ErrorDeseado? ===> %s\n%.3f   %.3f\n";
            s = String.format(s, (errorCalculado >= errorDeseado) ? "SI" : "NO",
                    errorCalculado, errorDeseado);
            txtaSalida.append(s);
        }
    }//GEN-LAST:event_btnIniciarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FrmIniciarEntrenamiento.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FrmIniciarEntrenamiento.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FrmIniciarEntrenamiento.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FrmIniciarEntrenamiento.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        /*java.awt.EventQueue.invokeLater(new Runnable() {
        
        @Override
        public void run() {
        FrmIniciarEntrenamiento dialog = new FrmIniciarEntrenamiento(new javax.swing.JFrame(), true);
        dialog.addWindowListener(new java.awt.event.WindowAdapter() {
        
        @Override
        public void windowClosing(java.awt.event.WindowEvent e) {
        System.exit(0);
        }
        });
        dialog.setVisible(true);
        }
        });*/
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnActualizar;
    private javax.swing.JButton btnGuardar;
    private javax.swing.JButton btnIniciar;
    private javax.swing.JButton btnSalir;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JToolBar.Separator jSeparator1;
    private javax.swing.JToolBar.Separator jSeparator2;
    private javax.swing.JLabel lblResultado;
    private javax.swing.JScrollPane scrollPane;
    private javax.swing.JTable tableMPesos;
    private javax.swing.JToolBar tbar;
    private javax.swing.JTextField txtBias;
    private javax.swing.JTextField txtError;
    private javax.swing.JTextField txtFactorAprendizaje;
    private javax.swing.JTextArea txtaSalida;
    // End of variables declaration//GEN-END:variables

    private void initDatos() {
        txtBias.setText(Double.toString(redAdalaine.getmPesos()[0][0]));
        txtFactorAprendizaje.setText(Double.toString(redAdalaine.getFactorAprendizaje()));
        txtError.setText(Double.toString(redAdalaine.getErrorEsperado()));

        // Inicializo la tabla
        List<Double> listPesos;
        String[] nombres;
        nombres = new String[redAdalaine.getNumNeurEntrada()];
        listPesos = new ArrayList<Double>(redAdalaine.getNumNeurEntrada() + 1);
        for (int i = 0; i < redAdalaine.getNumNeurEntrada(); i++) {
            listPesos.add(redAdalaine.getPeso(0, i + 1));
            nombres[i] = "Peso " + (i + 1);
        }

        tableMPesos.setModel(new ModeloTablaDatos(nombres, listPesos));
    }

    private String comparar(List<Double> listSalida, List<Double> listSalidaDeseada, int num) {
        if (listSalidaDeseada.get(0) == listSalida.get(num - 1)) {
            return "";
        }

        return "0";
    }

    private void mostrarResultados() {
        double[][] mPesos = redAdalaine.getmPesos();
        String s;
        System.out.print("Matriz de pesos:\n[ ");
        s = "Matriz de pesos: + " + "\n" + "[";
        txtaSalida.append(s);
        for (int i = 0; i < mPesos.length; i++) {
            for (int j = 0; j < mPesos[i].length; j++) {
                System.out.printf("%.4f  ", mPesos[i][j]);
                s = "%.4f  ";
                s = String.format(s, mPesos[i][j]);
                //s = mPesos[i][j] + "  ";
                txtaSalida.append(s);
            }
            System.out.print("]\n");
            s = "]\n";
            txtaSalida.append(s);
        }
    }
}
